Imports org.model.lib.db

''' <summary>
''' base class of Candidate Code generators
''' </summary>
''' <remarks></remarks>
Public MustInherit Class ICandidateCodeGenerator

    Public Function generateCandidateCode() As String

        If Me.periodClass.Period Is Nothing OrElse Me.periodClass.Period.PeriodId < 0 Then
            Throw New ApplicationException("An existing Period must be set in order to generate the candidate code.")
        End If

        ' step 1: if the student exists already we keep the code
        Dim lExistingCode As String = getExistingCandidateCode()
        If String.IsNullOrEmpty(lExistingCode) = False Then Return lExistingCode

        'step 2: if the student has no previous candidate code, generate a new code
        Return getNewCandidateCode()

    End Function

    ''' <summary>
    ''' Gets the next student counter, to be used to build the candidate code
    ''' </summary>
    Public MustOverride Function getStudentCounter() As Integer

    Public Property periodClass As IICModel.BusObjects.PeriodClass

    Public Property student As IICModel.BusObjects.Student

    ''' <summary>
    ''' Checks to see if the same student id has an existing candidate code for the
    ''' same diplomasupertypeid
    ''' </summary>
    Public MustOverride Function getExistingCandidateCode() As String

    ''' <summary>
    ''' Generate the new candidate code.  This function is called if getExistingCandidateCode returns null
    ''' </summary>
    Public MustOverride Function getNewCandidateCode() As String

End Class
